package com.gpframework.module.controller.ctn;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.core.page.TableDataInfo;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.common.utils.poi.ExcelUtil;
import com.gpframework.module.ctn.domain.GpSmsSendLog;
import com.gpframework.module.ctn.domain.req.GpSmsSendLogAdd;
import com.gpframework.module.ctn.domain.req.GpSmsSendLogReq;
import com.gpframework.module.ctn.domain.req.GpSmsSendLogUpdate;
import com.gpframework.module.ctn.domain.vo.GpSmsSendLogExcel;
import com.gpframework.module.ctn.domain.vo.GpSmsSendLogVo;
import com.gpframework.module.ctn.service.IGpSmsSendLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;
/**
 * @ClassName GpSmsSendLogController
 * @Author gpframework
 * @Date 2024-01-09
 * @Version 1.0.0
 * @Description 货柜到市场发送短信Controller
 */
@Validated
@Api(tags = "货柜到市场发送短信")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/ctn/smssendlog" )
public class GpSmsSendLogController extends BaseController {

    private final IGpSmsSendLogService iGpSmsSendLogService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2024-01-09
  * @Param gpSmsSendLog
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:list')")
    @GetMapping("/list")
    public TableDataInfo<GpSmsSendLogVo> list(GpSmsSendLogReq gpSmsSendLogReq)
    {
        startPage();
        QueryWrapper<GpSmsSendLog> lqw = new QueryWrapper<GpSmsSendLog>();
        gpSmsSendLogReq.generatorQuery(lqw,true);
        List<GpSmsSendLogVo> list = iGpSmsSendLogService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpSmsSendLog
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:add')" )
    @Log(title = "添加货柜到市场发送短信" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpSmsSendLogAdd gpSmsSendLogAdd) {
        GpSmsSendLog gpSmsSendLog = Convert.convert(new TypeReference<GpSmsSendLog>() {}, gpSmsSendLogAdd);
        return toAjax(iGpSmsSendLogService.save(gpSmsSendLog) ? 1 : 0);
    }


    /**
     * @Description 批量新增
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpSmsSendLog
     * @Return TableDataInfo
     */
    @ApiOperation("批量新增")
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:add')" )
    @Log(title = "批量新增货柜到市场发送短信" , businessType = BusinessType.INSERT)
    @PostMapping("/addBatch")
    public AjaxResult addBatch(@Valid @RequestBody GpSmsSendLogAdd gpSmsSendLogAdd) {
        if (StringUtils.isEmpty(gpSmsSendLogAdd.getGpSmsSendLogList())){
            return AjaxResult.parameterError();
        }
        return toAjax(iGpSmsSendLogService.addBatch(gpSmsSendLogAdd) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpSmsSendLog
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:edit')" )
    @Log(title = "修改货柜到市场发送短信" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpSmsSendLogUpdate gpSmsSendLogUpdate) {
        GpSmsSendLog gpSmsSendLog = Convert.convert(new TypeReference<GpSmsSendLog>() {}, gpSmsSendLogUpdate);
        return toAjax(iGpSmsSendLogService.updateById(gpSmsSendLog) ? 1 : 0);
    }


    /**
     * @Description 导出货柜到市场发送短信模板
     * @Author gpframework
     * @Date 2023-05-24
     * @Param gpCustomer
     * @Return TableDataInfo
     */
    @ApiOperation("导出货柜到市场发送短信模板")
    @Log(title = "导出货柜到市场发送短信模板" , businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:importTemplate')" )
    @GetMapping("/importTemplate" )
    public AjaxResult exportTemplate() {
        ExcelUtil<GpSmsSendLogExcel> util = new ExcelUtil<>(GpSmsSendLogExcel.class);
        return util.exportExcel(GpSmsSendLogExcel.list(), "模板");
    }

    /**
     * @Description 导入货柜到市场发送短信
     * @Author gpframework
     * @Date 2023-10-27
     * @Param (GpMember
     * @Return TableDataInfo
     */
    @Log(title = "导入货柜到市场发送短信" , businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:import')" )
    @PostMapping("/import" )
    public AjaxResult entityImport(MultipartFile file, Long brandId, Long storeId) throws Exception {
        ExcelUtil<GpSmsSendLogExcel> util = new ExcelUtil<GpSmsSendLogExcel>(GpSmsSendLogExcel. class);
        List<GpSmsSendLogExcel> excelList = util.importExcel(file.getInputStream());

        return AjaxResult.builder(() -> {
            return this.iGpSmsSendLogService.gpSmsSendLogImport(excelList, brandId, storeId);
        });
    }

    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpSmsSendLog
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:export')" )
    @Log(title = "导出货柜到市场发送短信" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpSmsSendLogReq gpSmsSendLogReq) {
        QueryWrapper<GpSmsSendLog> lqw = new QueryWrapper<GpSmsSendLog>();
        gpSmsSendLogReq.generatorQuery(lqw,true);
        List<GpSmsSendLogVo> list = iGpSmsSendLogService.listVo(lqw);
        ExcelUtil<GpSmsSendLogVo> util = new ExcelUtil<GpSmsSendLogVo>(GpSmsSendLogVo. class);
        return util.exportExcel(list, "smssendlog" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpSmsSendLog
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpSmsSendLogVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpSmsSendLogService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2024-01-09
     * @Param gpSmsSendLog
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('ctn:smssendlog:remove')" )
    @Log(title = "删除货柜到市场发送短信" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpSmsSendLogService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
